package com.example.dllo.my36kr.find.findpeople;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.news.NewsPicBean;
import com.example.dllo.my36kr.tools.NetTool;

import java.util.ArrayList;

/**
 * Created by dllo on 16/8/26.
 * 寻找投资人的Adapter
 */
public class PeopleAdapter extends BaseAdapter {
    Context mContext;
    PeopleBean bean;
    private final NetTool mNetTool;

    public void setBean(PeopleBean bean) {
        this.bean = bean;
    }

    public PeopleAdapter(Context mContext) {
        this.mContext = mContext;
        mNetTool = new NetTool();
    }

    @Override
    public int getCount() {
        return bean.getData().getData().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        PeopleHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.pepple_item,null);
            holder = new PeopleHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (PeopleHolder) convertView.getTag();
        }
        holder.nameTv.setText(bean.getData().getData().get(position).getUser().getName());
        mNetTool.getImage(bean.getData().getData().get(position).getUser().getAvatar(),holder.avatarIv);
        if (bean.getData().getData().get(position).getFocusIndustry().size() != 0) {
            ArrayList<String> list = new ArrayList<>();
            for (int i = 0; i < bean.getData().getData().get(position).getFocusIndustry().size(); i++) {
                list.add(bean.getData().getData().get(position).getFocusIndustry().get(i));
            }
            holder.focusIndustryTv.setText(list + "");
        }else {
            holder.focusIndustryTv.setText("未披露");
        }
        if (bean.getData().getData().get(position).getInvestPhases().size() != 0) {
            ArrayList<String> list = new ArrayList<>();
            for (int i = 0; i < bean.getData().getData().get(position).getInvestPhases().size(); i++) {
                list.add(bean.getData().getData().get(position).getInvestPhases().get(i));
            }
            holder.investPhasesTv.setText(list + "");
        }else {
            holder.investPhasesTv.setText("未披露");
        }

        return convertView;
    }
    public class PeopleHolder{
        ImageView avatarIv;
        TextView investPhasesTv,focusIndustryTv,nameTv;

        public PeopleHolder(View view) {
            avatarIv = (ImageView) view.findViewById(R.id.iv_people_avatar);
            investPhasesTv = (TextView) view.findViewById(R.id.tv_people_investPhases);
            focusIndustryTv = (TextView) view.findViewById(R.id.tv_people_focusIndustry);
            nameTv = (TextView) view.findViewById(R.id.tv_people_name);
        }
    }
}
